<?php
/*
 * @Author: CHINAKAIYUAN<sunkaiyuan@namenode.cn>
 * @Date: 2022-02-04 16:53:56
 * @LastEditTime: 2023-07-08 10:27:01
 * @LastEditors: 孙开源 && sunkaiyuan@namenode.cn
 * @Description: 
 */

namespace App\Http\Services\BaseData;

use App\Repositories\PointStickRepository;
use App\Http\Services\Service;
use Illuminate\Support\Facades\DB;

/**
 * @property PointStickRepository $repository 
 */
class PointStickService extends Service
    {
    public function boot(PointStickRepository $repository)
        {
        $this->repository = $repository;
        }

    public function list()
        {
        // DB::enableQueryLog();
        $data = $this->repository->condition(request())->getGrid();
        // dd(DB::getQueryLog());
        return $data;
        }
    protected function save()
        {
        if (!is_numeric(request()->loss_rate)) {
            fail("损耗率必须是数字！");
            }
        return $this->repository->autosave(request()->toArray());
        }
    protected function delete()
        {
        return $this->repository->whereIn("id", $this->getRequestIds())->get()->filter(function ($v)
            {
            if ($v->status_id != 0) {
                fail("请先禁用后删除！");
                }
            $v->delete();
            });
        }


    }